package com.thoughtworks.university.biblioteca;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * Created by sravanns on 10/06/14.
 */
public class BibliotecaApp
{
    static ArrayList<Book> checked_out_list=new ArrayList<Book>();

    static Scanner scan=new Scanner(System.in);
    public static void main(String[] args)
    {
        System.out.println(initialMessage());
        menu();
    }

    public static void menu() {
        int choice;
        do {
            System.out.println("1.List \n2.Check Out Book\n3.Return Book\n4.Quit");
            System.out.println("Enter option");
            choice=scan.nextInt();
            switch(choice)
            {
                case 1: new ListBooks().doAction();
                        break;

                case 2: System.out.println("enter book name");
                        String name=scan.next();
                        new CheckOut(name).doAction();
                        break;
                case 3: System.out.println("enter book name");
                        String name_return=scan.next();
                        new ReturnBook(name_return).doAction();
                        break;
                case 4: System.exit(0);
                default:System.out.println("Select a valid option!");

            }
        }
        while(true);
    }

    public static String initialMessage()
    {
        return "Welcome";
    }
    public boolean add(Book book)
    {
        //System.out.println("list is"+checked_out_list);
        int pointer=0;
        while(pointer<checked_out_list.size()) {
            if (checked_out_list.get(pointer).book_name.equalsIgnoreCase(book.book_name)) {
                return false;
            }
            pointer++;
        }
        checked_out_list.add(book);
        //System.out.println("list is"+checked_out_list);
        return true;

    }
    public boolean remove(Book book)
    {
        int pointer=0;
        int size=checked_out_list.size();
        while(pointer<size) {
            if (checked_out_list.get(pointer).book_name.equalsIgnoreCase(book.book_name)) {
                checked_out_list.remove(book);
                //System.out.println("list is"+checked_out_list);
                return true;
            }
            pointer++;
        }

        return false;

    }

}
